﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMessaging.Address;
using MMessaging.MessagingEx.Services;
using TUtils.BasicHelper;
using MMessaging.MessagingEx.Common;
using MMessaging.Address.Services;

namespace MMessaging.RequestResponse.Test.Services
{
	public class MyMathService : MAddressServiceBase, IMathOperationsFunctions
	{
		private MathOperationsPlugIn mathOperationsPlugIn;

		public MyMathService(
			MAddress serviceAddress,
			int intervallTime,
			IEnumerable<MAddress> roles
			): base(
				serviceAddress:serviceAddress,
				intervallTimeAlifeMessage:intervallTime, // time-intervall for alife-message
				// roles of this service
				roles:roles.ToArray())
		{
			mathOperationsPlugIn = new MathOperationsPlugIn(
				serviceAddress,
				this);

			this.RegisterPlugIn(
				mathOperationsPlugIn,
				PostMessage);
		}

		protected override void OnMessage(IMTask<MAddressMessageBase> context)
		{
		}

		void IMathOperationsFunctions.OnGetAddition(IMTask<MAddressMessageBase> task, GetAddition msg)
		{
			mathOperationsPlugIn.Send_GetAdditionResponse(
				msg,
				msg.Value1 + msg.Value2);
		}
	}
}
